import { PATHS as _PATHS } from "@/constants/path"
import { RoutesPages as Pages } from "@/pages"
import { accountRoutes } from "@/pages/AccountPage/routes"
import { forgetpasswordRoutes } from "@/pages/ForgetPassword/routes"
import {
    gameCategorySubPageRoutes,
    gameSectionsPageRoutes,
    homeSubPageRoutes,
} from "@/pages/HomePage/routes"
import { transactionRecordRoutes } from "@/pages/TransactionRecordPage/routes"
import { myRoutes } from "@/pages/UserCenterPage/routes"
import { welfareRoutes } from "@/pages/Walfare/routes"
import ENV from "@/utils/env"
import { RouteObject } from "react-router-dom"
import { AuthGuard } from "./AuthGuard"

export const PATHS = _PATHS

export const ROUTES_DEV: RouteObject[] = []

export const ROUTES_PROTECTED: RouteObject[] = [
    {
        path: "",
        Component: AuthGuard,
        children: [
            {
                path: PATHS.MY,
                lazy: Pages.UserCenterPage,
                children: [...myRoutes],
            },
            {
                path: PATHS.ACCOUNT,
                lazy: Pages.AccountPage,
                children: [...accountRoutes],
            },
            {
                path: PATHS.TRANSACTION,
                lazy: Pages.TransactionRecordPage,
                children: [...transactionRecordRoutes],
            },
            {
                path: PATHS.TRANSACTION_STATUS,
                lazy: Pages.TransactionStatusPage,
            },
            {
                path: PATHS.BET_RECORD,
                lazy: Pages.BetRecordPage,
            },
            {
                path: PATHS.WELFARE,
                children: [...welfareRoutes],
            },
            {
                path: PATHS.INVITE,
                lazy: Pages.InvitePage,
            },
            {
                path: PATHS.POINTS,
                lazy: Pages.PointsPage,
            },
            {
                path: PATHS.GAME_PAGE,
                lazy: Pages.GamePage,
            },
            {
                path: PATHS.WITHDRAW_ACCOUNTS,
                lazy: Pages.WithdrawAccounts,
            },
            {
                path: PATHS.KYC,
                async lazy() {
                    const { Component } = await Pages.KycPage()
                    return { Component }
                },
            },
        ],
    },
]

// 路由配置
export const ROUTES: RouteObject[] = [
    {
        path: PATHS.INDEX,
        lazy: Pages.HomePage,
        children: [...homeSubPageRoutes],
    },
    {
        path: PATHS.GAME_CATEGORY,
        lazy: Pages.HomePage,
        children: [...gameCategorySubPageRoutes],
    },
    {
        path: PATHS.SECTIONS,
        lazy: Pages.HomePage,
        children: [...gameSectionsPageRoutes],
    },
    {
        path: `${PATHS.LOGIN}`,
        lazy: Pages.LoginPageV2,
    },
    {
        path: PATHS.FORGET_PASSWORD,
        lazy: Pages.ForgetPasswordPage,
        children: [...forgetpasswordRoutes],
    },
    ...ROUTES_PROTECTED,
    ...(ENV.dev_mode ? ROUTES_DEV : []),
    {
        path: "*",
        lazy: Pages.NotFoundPage,
    },
]

console.log("ROUTES,", ROUTES)
